<!--
 * @Description: 墙布生产任务单
 *
 * @Author: guichengcai<guichengcai>
 * @Date: 2023-07-03 17:11:54
 * @FilePath: /yuxiuproweb/src/views/reportforms/sale/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="工单号" prop="workOrderNumber">
        <el-input
          v-model="queryParams.workOrderNumber"
          placeholder="请输入工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售单号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入销售单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工艺要求" prop="technology">
        <el-select
          style="width: 100%"
          v-model="queryParams.technology"
          filterable
          clearable
          placeholder="请选择工艺要求"
          @change="handleQuery"
        >
          <el-option label="冷胶" value="0"></el-option>
          <el-option label="热胶" value="1"></el-option>
          <el-option label="先冷后热" value="3"></el-option>
          <el-option label="无工艺" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="面料状态" prop="isShortageList">
        <el-select
          style="width: 100%"
          v-model="queryParams.isShortageList"
          filterable
          clearable
          placeholder="请选择面料状态"
          multiple
          @change="changeisShortageList"
          @clear="handleQuery"
        >
          <el-option label="空" value="6" />
          <el-option label="正常" value="0" />
          <el-option label="欠料" value="1" />
          <el-option label="零裁" value="2" />
          <el-option label="绣花" value="3" />
          <el-option label="绣花欠料" value="4" />
          <el-option label="包板" value="5" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <!-- <el-input
          v-model="queryParams.status"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          style="width: 100%"
          @change="handleQuery"
          clearable
        >
          <el-option label="确认" value="确认"></el-option>
          <el-option label="包装" value="包装"></el-option>
          <el-option label="发货" value="发货"></el-option>
          <el-option label="完结" value="完结"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="最近工序" prop="process">
        <el-select
          style="width: 100%"
          v-model="queryParams.process"
          filterable
          clearable
          placeholder="请选择最近工序"
          @change="handleQuery"
          @clear="handleQuery"
        >
          <el-option label="空" value="0" />
          <el-option label="裁剪" value="裁剪" />
          <el-option label="复合" value="复合" />
          <el-option label="包装" value="包装" />
          <el-option label="发货" value="发货" />
          <el-option label="已发货" value="已发货" />
        </el-select>
      </el-form-item>
      <el-form-item label="型号" prop="modelNumber">
        <el-input
          v-model="queryParams.modelNumber"
          placeholder="请输入型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="orderRemark">
        <el-input
          v-model="queryParams.orderRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货排单" prop="orderRemark">
        <el-select
          style="width: 100%"
          v-model="queryParams.isDelivery"
          placeholder="请选择是否排单"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option :label="'已排单'" value="1"></el-option>
          <el-option :label="'未排单'" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核日期" prop="createDate">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="queryParams.createDateObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          @change="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划日期" prop="planeDateObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="queryParams.planeDateObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          @change="handleQuery"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button-group style="margin-left: 10px">
          <el-button
            :type="!queryParams.accurate ? 'primary' : 'default'"
            @click="queryParams.accurate = false"
            size="mini"
            >模糊</el-button
          >
          <el-button
            :type="queryParams.accurate ? 'primary' : 'default'"
            @click="queryParams.accurate = true"
            size="mini"
            >精确</el-button
          >
        </el-button-group>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['qb:order:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleHaveAdd"
          v-hasPermi="['qb:order:add']"
          >备料新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pro:record:export']"
          >导出</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="handleSchedule('intendedDate')"
          >计划排单</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="handleSchedule('deliveryTime')"
          >发货排单</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-position"
          size="mini"
          @click="handlePush('push')"
          >推送</el-button
        >
        <!-- <el-button
          type="warning"
          plain
          icon="el-icon-position"
          size="mini"
          @click="handlePush('back')"
          >回退</el-button
        > -->
        <el-button
          type="primary"
          plain
          icon="el-icon-position"
          size="mini"
          @click="handleoutGoing"
          >转外发</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      ref="tableList"
      v-loading="loading"
      :data="recordList"
      :row-class-name="tableRowClassName"
      @selection-change="handleSelectionChange"
      @sort-change="sortFun"
      :max-height="maxHeight"
      show-summary
      :summary-method="getSummaries"
      :span-method="objectSpanMethod"
      :row-style="{ height: '20px' }"
      :cell-style="{ padding: '0px', 'font-size': '15px' }"
      border
      size="mini"
    >
      <el-table-column type="selection" width="55" align="center" fixed />
      <template v-for="(i, index) in tableForm.item">
        <el-table-column
          :key="index"
          :prop="i.itemcode"
          :columnKey="i.itemcode"
          :label="i.itemname"
          :align="i.aligntype ? i.aligntype : 'center'"
          :width="!!i.width ? i.width : ''"
          :min-width="i.minwidth"
          :show-overflow-tooltip="i.overflow ? true : false"
          :sortable="i.sortable ? true : false"
          :fixed="i.fixed"
          v-if="i.displaymark ? true : false"
        >
          <template slot-scope="scope">
            <el-button
              v-if="i.itemcode == 'workOrderNumber'"
              type="text"
              @click="handleDetail(scope.row)"
            >
              <strong style="font-size: 16px">{{
                scope.row[i.itemcode]
              }}</strong>
            </el-button>
            <div v-else-if="i.itemcode == 'isUrgent'">
              <span v-if="scope.row[i.itemcode] == 1">是</span>
              <span v-else>否</span>
            </div>
            <div v-else-if="i.itemcode == 'technology'">
              <span v-if="scope.row[i.itemcode] == 0">冷胶</span>
              <span v-else-if="scope.row[i.itemcode] == 1">热胶</span>
              <span v-else-if="scope.row[i.itemcode] == 3">先冷后热</span>
              <span v-else>无工艺</span>
            </div>
            <div v-else-if="i.itemcode == 'deliveryMethod'">
              <span v-if="scope.row['postageModeOfPayment'] == 0"
                >{{ scope.row[i.itemcode] }}(寄付)</span
              >
              <span v-else-if="scope.row['postageModeOfPayment'] == 1"
                >{{ scope.row[i.itemcode] }}(到付)</span
              >
              <span v-else-if="scope.row['postageModeOfPayment'] == 2"
                >{{ scope.row[i.itemcode] }}(包邮)</span
              >
            </div>
            <div v-else-if="i.itemcode == 'isUsingRebate'">
              <span v-if="scope.row[i.itemcode] == 1">是</span>
              <span v-else>否</span>
            </div>
            <div v-else-if="i.itemcode == 'isShortage'">
              <span v-if="scope.row[i.itemcode] == 1" style="color: red"
                >欠料</span
              >
              <span v-else-if="scope.row[i.itemcode] == 2" style="color: red"
                >零裁</span
              >
              <span v-else-if="scope.row[i.itemcode] == 3">绣花</span>
              <span v-else-if="scope.row[i.itemcode] == 4" style="color: red"
                >绣花欠料</span
              >
              <span v-else-if="scope.row[i.itemcode] == 5" style="color: red"
                >包板</span
              >
              <span v-else-if="scope.row[i.itemcode] == 0">正常</span>
              <span v-else-if="scope.row[i.itemcode] == 6">空</span>
            </div>

            <span v-else>{{ scope.row[i.itemcode] }}</span>
          </template>
        </el-table-column>
      </template>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改订单对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList"
    ></add-view>
    <detail-view
      v-if="detailopen.show"
      :show.sync="detailopen.show"
      v-bind="detailopen"
      @update="getList"
    ></detail-view>
    <!-- 排单 -->
    <el-dialog
      :title="plandateType == 'intendedDate' ? '计划排程' : '发货排程'"
      :append-to-body="true"
      width="400px"
      :visible.sync="scheduleVisible"
      :close-on-click-modal="false"
      class="paichengDialog"
    >
      <div style="display: flex">
        <el-date-picker
          style="width: 100%; margin-right: 10px; flex: 1"
          v-model="plandate"
          type="date"
          placeholder="YYYY-MM-DD"
        ></el-date-picker>
        <!-- :picker-options="pickerOptions" -->
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="submitSchedule()"
          >确 定</el-button
        >
        <el-button size="small" @click="scheduleVisible = false"
          >取 消</el-button
        >
      </div>
    </el-dialog>
    <!-- 备货新增 -->
    <el-dialog
      title="备货新增"
      :append-to-body="true"
      width="80vw"
      :visible.sync="haveopen.show"
      :close-on-click-modal="false"
    >
      <HaveAddView ref="HaveAddView" @update="getList"></HaveAddView>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="submithaveAdd()"
          >确 定</el-button
        >
        <el-button size="small" @click="haveopen.show = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRecord,
  addTaskOrder,
  updateTaskOrder,
  getTaskOrder,
} from "@/api/qb";
import commonMix from "@/utils/mixins/common";
import { listBrand } from "@/api/money/brand";
import { listClient, getClient } from "@/api/mes/md/client";
import { tableList } from "./mods/tablecolums.js";
import AddView from "./mods/add.vue";
import DetailView from "./mods/detail.vue";
import HaveAddView from "./mods/haveAdd.vue";
export default {
  mixins: [commonMix],
  dicts: ["pro_order_state"],
  name: "Record",
  components: { AddView, DetailView, HaveAddView },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      detailopen: {
        show: false,
        data: null,
      },
      haveopen: {
        show: false,
        data: null,
      },
      clientList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderType: "YC",
        orderId: null,
        clientId: null,
        clientName: null,
        cashAccount: null,
        rebateAccount: null,
        otherAccount: null,
        technology: null,
        isShortage: null,
        status: null,
        isShortageList: [],
        process: null,
        number: null,
        workOrderNumber: null,
        modelNumber: null,
        accurate: false,
      },
      brandList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 排单
      scheduleVisible: false,
      plandate: null,
      plandateType: null,
      selRow: [],
      // 禁用今天以前的日期
      pickerOptions: {
        disabledDate(v) {
          return v.getTime() < new Date().getTime() - 86400000; //  - 86400000是否包括当天
        },
      },
      //
      tableForm: tableList,
      mergeObj: {}, // 用来记录需要合并行的下标
      mergeArr: ["number"], // 表格中的列名
    };
  },
  created() {
    this.getListClient();
    this.getList();
  },
  mounted() {},
  methods: {
    /** 提交按钮  已废弃*/
    async submitForm() {
      await this.$refs["form"].validate();
      const { data } = await getClient(this.form?.clientId);

      const query = {
        ...this.form,
        clientName: data.clientName,
        area: data.province,
        contactNumber: data.tel,
        contacts: data.clientName,
        salesman: data.contact1,
        orderDate: this.form.createDate,
        isUsingRebate: this.form.isUsingRebate[0],
        isUrgent: this.form.isUrgent[0],
      };

      if (this.form.proOrderId != null) {
        updateTaskOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
          this.goPages(data);
        });
      } else {
        addTaskOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
          this.goPages(data);
        });
      }
    },
    changeisShortageList(val) {
      this.queryParams.isShortageList = val;
    },
    getListClient(clientName = "") {
      listClient({
        pageNum: 1,
        pageSize: 100,
        enableFlag: "Y",
        clientName,
        // id: "1107",
      }).then(({ rows }) => {
        this.clientList = rows;
      });
    },
    handleClientChange() {
      const { province, city, district, address, tel } = this.clientList?.find(
        (e) => e.clientId === this.form.clientId
      );
      this.form.address = `${province || ""}${city || ""}${district || ""}${
        address || ""
      }`;
      this.form.tel = tel;
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      const datarow = { ...row } || null;
      this.open = {
        show: true,
        type: "add",
        data: datarow,
      };
    },
    // 修改
    handleDetail(row) {
      const datarow = { ...row } || null;
      this.detailopen = {
        show: true,
        data: datarow,
      };
    },
    /** 查询生产任务列表 */
    getList() {
      this.loading = true;
      const params = {
        ...this.queryParams,
        startDate: this.queryParams.createDateObj?.[0] || null,
        endDate: this.queryParams.createDateObj?.[1] || null,
        startIntendedDate: this.queryParams.planeDateObj?.[0] || null,
        endIntendedDate: this.queryParams.planeDateObj?.[1] || null,
      };
      delete params.createDateObj;
      delete params.planeDateObj;
      listRecord(params).then((response) => {
        this.recordList = this.getSpanArr(
          response.rows,
          "number",
          "dealRowSpan"
        );
        for (var i = 0; i < this.recordList.length; i++) {
          var item = this.recordList[i];
          item.productionTaskId = Number(item.productionTaskId);
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.productionTaskId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.selRow = selection;
    },

    /** 导出按钮操作 */
    handleExport() {
      if (!this.ids.length) {
        this.$message.error("请勾选要导出的任务单");
        return;
      }
      var idsArr = [];
      for (var i = 0; i < this.ids.length; i++) {
        var item = this.ids[i];
        var obj = {
          productionTaskId: item,
        };
        idsArr.push(obj);
      }
      this.downloadExcel(
        "qb/task/export",
        idsArr,
        `墙布任务单_${new Date().getTime()}.xlsx`
      );
      this.$refs.tableList.clearSelection();
    },
    // 排单
    handleSchedule(code) {
      if (this.selRow.length == 0) {
        this.$message.error("请勾选单据");
        return;
      }
      this.scheduleVisible = true;
      this.plandateType = code;
      this.plandate = null;
      // 判断勾选的是否有计划时间
      if (this.selRow.length == 1) {
        this.selRow[0][code]
          ? (this.plandate = this.selRow[0][code])
          : (this.plandate = null);
      }
    },
    // 转外发
    async handleoutGoing() {
      let promiseList = [];
      for (var i = 0; i < this.selRow.length; i++) {
        var item = this.selRow[i];
        var that = this;
        let promise = new Promise((resolve, reject) => {
          // item.intendedDate = that.dateFormats(that.plandate);
          item.status = "外发";
          updateTaskOrder(item)
            .then((res) => {
              resolve(res || "外发成功");
            })
            .catch((er) => {
              // reject("操作失败");
            });
        });
        promiseList.push(promise);
      }
      await Promise.all(promiseList)
        .then((res) => {
          console.log("等所有异步请求完成后执行", res);
          // 等所有异步请求完成后执行
          this.$modal.msgSuccess(res.msg || "外发成功");
          // this.scheduleVisible = false;
        })
        .catch((er) => {})
        .finally(() => {
          this.getList();
        });
    },
    // 推送
    async handlePush(operateType) {
      // 状态(确认,欠料,暂停,绣花,绣花欠料,包版,外发,下架)
      let promiseList = [];
      for (var i = 0; i < this.selRow.length; i++) {
        var item = this.selRow[i];
        var that = this;
        if (item.status != "完结") {
          let promise = new Promise((resolve, reject) => {
            if (operateType == "back") {
              item.status = "确定";
              item.deliveryTime = "-1";
            } else {
              item.status = "发货";
              if (!item.deliveryTime) {
                item.deliveryTime = this.dateFormats(new Date());
              }
            }
            updateTaskOrder(item)
              .then((res) => {
                resolve(
                  res || (operateType == "back" ? "回退" : "推送") + "成功"
                );
              })
              .catch((er) => {
                // reject("操作失败");
              });
          });
          promiseList.push(promise);
        } else {
          // this.$message.error("该订单已完结！");
          reject("该订单已完结！");
          break;
        }
      }
      await Promise.all(promiseList)
        .then((res) => {
          console.log("等所有异步请求完成后执行", res);
          // 等所有异步请求完成后执行
          this.$modal.msgSuccess(
            res.msg || (operateType == "back" ? "回退" : "推送") + "成功"
          );
          // this.scheduleVisible = false;
        })
        .catch((er) => {
          this.$message.error(er);
        })
        .finally(() => {
          this.getList();
        });
    },
    //提交，修改计划时间
    async submitSchedule() {
      // const data = await this.getTaskOrderData(this.ids[0].proOrderId);
      //  修改时间保存
      let isErr = [];
      let promiseList = [];
      for (var i = 0; i < this.selRow.length; i++) {
        var item = this.selRow[i];
        var that = this;
        let promise = new Promise((resolve, reject) => {
          if (item.process != "已发货" || item.status != "完结") {
            if (this.plandateType == "intendedDate") {
              item.intendedDate = !!that.plandate
                ? that.dateFormats(that.plandate)
                : "";
            } else {
              item.deliveryTime = !!that.plandate
                ? that.dateFormats(that.plandate)
                : "";
              if (item.status != "发货") {
                item.status = "发货";
              } else {
                if (item.deliveryTime == "") {
                  item.status = "确认";
                }
              }
            }
            updateTaskOrder(item)
              .then((res) => {
                resolve(res || "排单成功");
              })
              .catch((er) => {
                reject(er || "操作失败");
              });
          } else {
            isErr.push(item.workOrderNumber);
            reject(isErr);
          }
        });
        promiseList.push(promise);
      }
      await Promise.all(promiseList)
        .then((res) => {
          this.$modal.msgSuccess(res.msg || "排单成功");
          this.scheduleVisible = false;
        })
        .catch((er) => {
          this.$message.error(
            er || "操作失败！" + isErr.length ? +isErr + "该工单已完结！" : ""
          );
        })
        .finally(() => {
          this.getList();
        });
    },
    // 获取数据
    async getTaskOrderData(proOrderId) {
      const { data } = await getTaskOrder(proOrderId);
      return data;
    },
    dateFormats(dataStr) {
      if (!dataStr) {
        return;
      }
      var dt = new Date(dataStr);
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, "0");
      var d = dt.getDate().toString().padStart(2, "0");
      var hh = dt.getHours().toString().padStart(2, "0");
      var mm = dt.getMinutes().toString().padStart(2, "0");
      var ss = dt.getSeconds().toString().padStart(2, "0");
      return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
    },
    getSummaries(param) {
      const { columns, data } = param;
      var arr = ["length"];
      const sums = [];
      columns.forEach((column, index) => {
        var bor = false;
        if (
          arr.length > 0 &&
          arr.find((item) => item == column.property) != undefined
        ) {
          bor = true;
        }
        if (index === 1) {
          sums[index] = "合计";
        } else {
          const values = data.map((item) => Number(item[column.property]));
          if (!values.every((value) => isNaN(value)) && bor) {
            sums[index] = Number(
              values
                .reduce((prev, curr) => {
                  const value = Number(curr);
                  if (!isNaN(value)) {
                    return prev + curr;
                  } else {
                    return prev;
                  }
                }, 0)
                .toFixed(2)
            );
          }
        }
      });
      return sums;
    },
    // 备料新增
    handleHaveAdd() {
      this.haveopen.show = true;
      this.$nextTick(() => {
        this.$refs.HaveAddView.lst = [];
      });
    },
    async submithaveAdd() {
      var paramArr = this.$refs.HaveAddView.lst;
      // this.$refs.HaveAddView.form
      let promiseList = [];
      for (var i = 0; i < paramArr.length; i++) {
        var item = paramArr[i];
        var that = this;
        let promise = new Promise((resolve, reject) => {
          item.clientName = that.$refs.HaveAddView.form.clientName;
          item.isUrgent = that.$refs.HaveAddView.form.isUrgent;
          addTaskOrder(item)
            .then(({ data }) => {
              resolve(res || "操作成功");
            })
            .catch((er) => {
              reject("操作失败");
            });
        });
        promiseList.push(promise);
      }
      await Promise.all(promiseList)
        .then((res) => {
          console.log("等所有异步请求完成后执行", res);
          // 等所有异步请求完成后执行
          this.$modal.msgSuccess(res.msg || "操作成功");
          this.haveopen.show = false;
        })
        .catch((er) => {})
        .finally(() => {
          this.getList();
        });
    },
    sortFun({ column, prop, order }) {
      this.queryParams.sortName = prop;
      if (order == "descending") {
        this.queryParams.sort = "desc";
      } else if (order == "ascending") {
        this.queryParams.sort = "asc";
      } else {
        this.$delete(this.queryParams, "sortName");
        this.$delete(this.queryParams, "sort");
      }
      this.getList();
    },
    getSpanArr(list, code, rowSpan, isSort) {
      let arrZero = [];
      return list.map((item, i) => {
        let RowSpanNum = 1;
        for (let j = i + 1; j < list.length; j++) {
          if (item[code] === list[j][code]) {
            arrZero.push(j);
            RowSpanNum++;
          } else {
            break;
          }
        }
        if (arrZero.findIndex((ele) => ele == i) != -1) {
          RowSpanNum = 0;
        }
        return {
          ...item,
          [rowSpan]: RowSpanNum,
        };
      });
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (column.columnKey == "number" || column.columnKey == "clientName") {
        return {
          rowspan: row.dealRowSpan,
          colspan: 1,
        };
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.process == "裁剪") {
        return "green-row"; //'success-row'
      } else if (row.process == "复合") {
        return "yellow-row";
      } else if (row.process == "包装") {
        return "blue-row";
      } else if (row.process == "发货") {
        return "pink-row";
      } else if (row.process == "已发货") {
        return "gray-row";
      }
      return "";
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-table .yellow-row {
  background: #ffba00;
}

::v-deep .el-table .green-row {
  background: #adf489;
}
::v-deep .el-table .blue-row {
  background: #a3d3ff;
  // color: #fff;
  // .el-button--text {
  //   color: #fff;
  // }
}
::v-deep .el-table .pink-row {
  background: #fdd3fb;
}
::v-deep .el-table .gray-row {
  background: #cecece;
}
</style>
